<?php

    include_once '../clases/Programacion.php';
    
    $tc = $_REQUEST['tc'];
    
    if($tc == 1){
        
        $prog = new Programacion("", "", "", "", "", "", "");
        $prog->programaciones();
        
    }else if($tc == 2){
        
        $sel1 = $_REQUEST['sel1'];
        $sel2 = $_REQUEST['sel2'];
        $res1 = $_REQUEST['res1'];
        $res2 = $_REQUEST['res2'];
        
        $fechae = $_REQUEST['fechaen'];
        $fecha = date('Y-m-d H:i:s',strtotime($fechae));
        
        $prog = new Programacion("", $sel1, $sel2, $res1, $res2, $fecha, "");
        
        $prog->insertarProg();
        
    }else if($tc == 3){
        
        $sel1 = $_REQUEST['sel1'];
        $sel2 = $_REQUEST['sel2'];
        $res1 = $_REQUEST['res1'];
        $res2 = $_REQUEST['res2'];
        $oidp = $_REQUEST['oidp'];
        
        $fechae = $_REQUEST['fechaen'];
        $fecha = date('Y-m-d H:i:s',strtotime($fechae));
        
        $pro = new Programacion($oidp, $sel1, $sel2, $res1, $res2, $fecha, "");
        $pro->editarProg();
        
    }else if($tc == 4){
        
        $oidp = $_REQUEST['oid'];
        $estado = $_REQUEST['estado'];
        
        $pro = new Programacion($oidp, "", "", "", "", "", $estado);
        $pro->activacion();
        
    }else if($tc == 5){
        
        $oidp = $_REQUEST['oidp'];
        
        $pro = new Programacion($oidp, "", "", "", "", "", "");
        $pro->consultaFecha();
        
    }else if($tc == 6){
        
        $oidp = $_REQUEST['oidp'];
        
        include_once '../clases/Conexion.php';
        
        $con = new Conexion();
        
        $update = "select DATEDIFF(MINUTE,GETDATE(),PROGRAMACION.FECHA) as fecha
                   from PROGRAMACION LEFT OUTER JOIN POLLA ON PROGRAMACION.OID = POLLA.PROGRAMACION
                   WHERE POLLA.OID = ".$oidp;
        $res = $con->query($update);
        
        while($res2 = mssql_fetch_array($res)){
            
            $minutos = $res2['fecha'];
            
        }
        
        print_r(json_encode(array('respuesta'=>$minutos)));
        
        $con->cerrarConexion();
        
    }

?>
